<?php
namespace app\task\controller;

use app\common\cache\user\IUserCache;
use app\common\enum\AppType;
use app\common\enum\PoolBidStatus;
use app\common\ext\IConfig;
use app\common\ext\IDb;
use app\common\ext\IJPush;
use app\common\ext\ISms;

class TenderStop{

    /**
     * @功能：意向用户开发
     * @开发者：cxl
     */
    public function index(){
        //设置php执行时间，直到执行结束为止
        set_time_limit(0);

        $open_hour = get_config('OpenBidDate');
        if($open_hour <= 0){
            $open_hour = 24;
        }

        $time = date('Y-m-d H:i:s',strtotime("-{$open_hour}hour +20 minute"));

        //取得待开发的客户
        $user_pool_bid_where["pool_bid_status"] = PoolBidStatus::BidDown;
        $user_pool_bid_where["date_format(bid_end,'%Y-%m-%d %H:%i:%s')"] = array("egt",$time);
        $user_pool_bid_where["bid_end"] = array("elt",get_date_time());
        $user_pool_bid_list = IDb::getInstance('user_pool_bid')
            ->setDbFiled("cooperate_admin_id,bid_end")
            ->setDbWhere($user_pool_bid_where)
            ->sel();
        if($user_pool_bid_list === false){
            exit("Fail");
        }

        //判断数据是否存在
        if(!empty($user_pool_bid_list) && is_array($user_pool_bid_list)){
            //循环发送消息
            foreach($user_pool_bid_list as $item){
                //取得用户信息
//                $user_phone = IUserCache::getInfo($item['user_id'],"phone");

                //发送短信
//                ISms::Send($user_phone,ISms::PrTenderStop,array($item['bid_end']));

                $bid_expire = date('Y-m-d H:i',strtotime($item['bid_end']."+{$open_hour} hour"));

                //发送推送信息
                IJPush::Push(AppType::HZ,"派单截止！","【有度合作商】您的订单信息将于{$bid_expire}截止派单，请尽快派单；",$item['cooperate_admin_id']);
            }
        }

        //返回值
        exit("Success");
    }
}
